package com.kkd.kkdapp.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.MyBaseAdapter;
import com.kkd.kkdapp.http.entity.DiscountCoupon;

public class TenderAffirmDiscountCouponAdapter extends
		MyBaseAdapter<DiscountCoupon> {
	private List<DiscountCoupon> sList;
	private int mPosition = 0;

	public TenderAffirmDiscountCouponAdapter(Context context) {
		super(context);
		sList = this.getAdapterData();
	}

	class ViewHolder {

		// ImageView icon_img;
		TextView icon_tv;
		TextView bg_tv;

	}

	@Override
	public View getMyView(int position, View convertView, ViewGroup parent) {
		final ViewHolder mViewHolder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.coupongridview_item,
					null);
			mViewHolder = new ViewHolder();
			// mViewHolder.icon_img = (ImageView) convertView
			// .findViewById(R.id.icon_img);
			mViewHolder.icon_tv = (TextView) convertView
					.findViewById(R.id.icon_tv);
			mViewHolder.bg_tv = (TextView) convertView.findViewById(R.id.bg_tv);
			convertView.setTag(mViewHolder);
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}
		mViewHolder.icon_tv.setText(sList.get(position).getCouponName());
		if ("期待中".equals(sList.get(position).getCouponName())) {
			mViewHolder.icon_tv.setTextColor(context.getResources().getColor(
					R.color.gray_999999));
			//mViewHolder.icon_img.setVisibility(View.GONE);
		} else {
			//mViewHolder.icon_img.setVisibility(View.VISIBLE);
			//mViewHolder.icon_img.setImageResource(sList.get(position)
			//		.getCouponimg());
		}
		mViewHolder.bg_tv.setBackgroundResource(R.color.violet_ddd8ec);
		if (mPosition != position) {
			mViewHolder.bg_tv.setBackgroundResource(R.color.white);
		}
		if (position != 4 && position != 5) {
			convertView.setOnClickListener(new MyOnclick(position,
					mViewHolder.bg_tv));
		}
		return convertView;
	}

	class MyOnclick implements OnClickListener {

		private int position;
		private TextView tv;

		public MyOnclick(int position, TextView tv) {
			this.position = position;
			this.tv = tv;
		}

		@Override
		public void onClick(View v) {
			if (mOnItemCliclistener != null) {
				mOnItemCliclistener.onPosition(position);
				tv.setBackgroundResource(R.color.violet_ddd8ec);
				mPosition = position;
			}
		}
	}

	public void setonItemClickListener(OnItemCliclistener callback) {
		mOnItemCliclistener = callback;
	}

	public OnItemCliclistener mOnItemCliclistener;

	public interface OnItemCliclistener {
		public void onPosition(int id);
	}
}
